<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>代理管理</title>
	<meta name="decorator" content="default"/>
	<link rel="stylesheet" href="${ctxStatic}/distpicker/css/main.css">
	<script src="${ctxStatic}/jquery/jquery-1.9.1.min.js"></script><!-- jQuery is required -->
	<script src="${ctxStatic}/distpicker/js/distpicker.data.js"></script>
	<script src="${ctxStatic}/distpicker/js/distpicker.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
            
			$("#company").focus();
			// 省、市、区级联
			$("#province").change(function(){
				var provinceCode = $(this).children('option:selected').attr("data-code");
				var provinceName = $(this).children('option:selected').val();
				$("#provinceCode").val(provinceCode);
				$("#provinceName").val(provinceName);
				
				var cityCode = $("#city").find('option:selected').attr("data-code");
				var cityName = $("#city").find('option:selected').val();
				$("#cityCode").val(cityCode);
				$("#cityName").val(cityName);
				
				var districtCode = $("#district").find('option:selected').attr("data-code");
				var districtName = $("#district").find('option:selected').val();
				$("#districtCode").val(districtCode);
				$("#districtName").val(districtName);
			});
			// 市、区级联
			$("#city").change(function(){
				var cityCode = $(this).children('option:selected').attr("data-code");
				var cityName = $(this).children('option:selected').val();
				$("#cityCode").val(cityCode);
				$("#cityName").val(cityName);
				
				var districtCode = $("#district").find('option:selected').attr("data-code");
				var districtName = $("#district").find('option:selected').val();
				$("#districtCode").val(districtCode);
				$("#districtName").val(districtName);
			});
			
			$("#district").change(function(){
				var districtCode = $(this).children('option:selected').attr("data-code");
				var districtName = $(this).children('option:selected').val();
				$("#districtCode").val(districtCode);
				$("#districtName").val(districtName);
			});
			
			var id = '${agent.id}';
			if(id != null && id != ""){
				
				// 地区回显
				var provinceCode = '${agent.provinceCode}';
				var provinceName = '${agent.provinceName}';
				var cityCode = '${agent.cityCode}';
				var cityName = '${agent.cityName}';
				var districtCode = '${agent.districtCode}';
				var districtName = '${agent.districtName}';
				/* 
				$("#distpicker").distpicker({province: '河北省', city: '石家庄市', district: '长安区'});
				*/
				
				$("#areaSelectBody").css("display", "none");
				$("#areaDisplayBody").css("display", "block");
				$("#area").val(provinceName+" "+cityName+" "+districtName);
				
				// 审核状态回显
				var status = '${agent.status}';
				if(status == '2'){ // 拒绝
					$("#remarkBody").css("display", "block");
				} else {
					$("#remarkBody").css("display", "none");
				}
			} else {
				$("#areaSelectBody").css("display", "block");
				$("#areaDisplayBody").css("display", "none");
				
				// 审核状态默认选中为"待定"
				$("input:radio[name=status][value='0']").attr("checked", true);
			}
			
		});
		
		/**
		* 地区重置
		*/
		function areaReset(){
			
			$("#areaSelectBody").css("display", "block");
			$("#areaDisplayBody").css("display", "none");
			$("#distpicker").distpicker('reset', true);
		}
		
		/**
		* 审核状态改变
		*/
		function statusChange(){
			
			$(".auditSelect").each(function(){
				if($(this).is(":checked")){
					var status = $(this).val();
					if(status == '2'){ // 拒绝
						$("#remarkBody").css("display", "block");
					} else {
						$("#remarkBody").css("display", "none");
					}
				}
			});
			
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/pay/agent/">代理列表</a></li>
		<li class="active"><a href="<c:url value='${fns:getAdminPath()}/pay/agent/form?id=${agent.id}'></c:url>">代理${not empty agent.id?'修改':'添加'}</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="agent" action="${ctx}/pay/agent/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">公司:</label>
			<div class="controls">
				<form:input path="company" htmlEscape="false" maxlength="200" class="input-xxlarge measure-input required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">地区:</label>
			<div id="areaSelectBody" class="controls">
				<div data-toggle="distpicker">
				  <select id="province" class="input-small" data-province="---- 选择省 ----"></select>
  				  <select id="city" class="input-small" data-city="---- 选择市 ----"></select>
  				  <select id="district" class="input-small" data-district="---- 选择区 ----"></select>
  				  <input type="hidden" id="provinceCode" name="provinceCode" value="${agent.provinceCode}" />
  				  <input type="hidden" id="provinceName" name="provinceName" value="${agent.provinceName}" />
  				  <input type="hidden" id="cityCode" name="cityCode" value="${agent.cityCode}" />
  				  <input type="hidden" id="cityName" name="cityName" value="${agent.cityName}" />
  				  <input type="hidden" id="districtCode" name="districtCode" value="${agent.districtCode}" />
  				  <input type="hidden" id="districtName" name="districtName" value="${agent.districtName}" />
				</div>
			</div>
			<div id="areaDisplayBody" class="controls" style="display:none;">
				<input type="text" readonly="readonly" maxlength="20" class="input-xlarge" name="area" id="area"/>
				<input id="btnReset" class="btn btn-warning" type="button" value="重 置" onclick="areaReset()"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">姓名:</label>
			<div class="controls">
				<form:input path="realName" htmlEscape="false" maxlength="200" class="input-xxlarge required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">邮箱:</label>
			<div class="controls">
				<form:input path="email" htmlEscape="false" maxlength="200" class="input-xxlarge required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">QQ:</label>
			<div class="controls">
				<form:input path="qq" htmlEscape="false" maxlength="200" class="input-xxlarge required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">电话:</label>
			<div class="controls">
				<form:input path="phone" htmlEscape="false" maxlength="200" class="input-xxlarge"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">审核:</label>
			<div class="controls">
				<form:radiobuttons path="status" items="${fns:getDictList('pay_agent_audit')}" itemLabel="label" itemValue="value" onchange="statusChange();" htmlEscape="false" class="auditSelect required"/>
				<span class="help-inline"></span>
			</div>
		</div>
		<div id="remarkBody" class="control-group" style="display:none;">
			<label class="control-label">备注:</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="200" class="input-xxlarge"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">发布时间:</label>
			<div class="controls">
				<input id="createDate" name="createDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
					value="<fmt:formatDate value="${agent.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">发布状态:</label>
			<div class="controls">
				<form:radiobuttons path="delFlag" items="${fns:getDictList('cms_del_flag')}" itemLabel="label" itemValue="value" htmlEscape="false" class="required"/>
				<span class="help-inline"></span>
			</div>
		</div>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>